package com.type.dao;

import java.util.ArrayList;
import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import com.comm.Utilities;
import com.type.vo.AdminManageBoardVO;

/**
 * 관리자용 게시판 CRUD Service 클래스
 * admin_board DB에서 값을 가져온다.
 * @author daou-ljhjoin
 *
 */
@Repository("AdminManageBoardDAO")
public class AdminManageBoardDAO {
	@Resource(name="sqlMapClientTemplate")
	private SqlMapClientTemplate sqlmap;
	
	public int selectBoardNo(){
		return (Integer) sqlmap.queryForObject("adminBoard.selectBoardNo");
	}
	
	public void insertAdminBoard(AdminManageBoardVO board){
		sqlmap.insert("adminBoard.insertAdminBoard",board);
	}
	public AdminManageBoardVO selectAdminBoardByNo(int boardNo){
		return (AdminManageBoardVO) sqlmap.queryForObject("adminBoard.selectAdminBoardByNo", boardNo);
	}
	public void updateAdminBoard(AdminManageBoardVO board){
		sqlmap.update("adminBoard.updateAdminBoard",board);
	}
	public void deleteAdminBoardByNo(int boardNo){
		sqlmap.delete("adminBoard.deleteAdminBoard",boardNo);
	}
	public int getTotalCountOfBoard(){
		return (Integer) sqlmap.queryForObject("adminBoard.selectTotalAdminBoard");
	}
	
	/*
	 * 관리자용화면 게시판 전체 리스트 출력
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<AdminManageBoardVO> selectAdminBoardAllListByPaging(int page){
		HashMap map = new HashMap();
		map.put("page", page);
		map.put("perPage", Utilities.CONTENT_PER_PAGE);
		return (ArrayList<AdminManageBoardVO>) sqlmap.queryForList("adminBoard.selectAdminBoardByPage",map);
	}
	
	/*
	 * 관리자용 화면 게시판 검색조건에 따른 리스트 출력
	 * (검색조건 : boardType , adminName)
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<AdminManageBoardVO> searchAdminNameByPaging(int page, String boardType, String adminName){
		HashMap map = new HashMap();
		map.put("page", page);
		map.put("perPage", Utilities.CONTENT_PER_PAGE);
		map.put("boardType", boardType);
		map.put("adminName", adminName);
		return (ArrayList<AdminManageBoardVO>) sqlmap.queryForList("adminBoard.SearchAdminNameByPage",map);
	}
	/*
	 * 관리자용 화면 게시판 검색조건에 따른 리스트 출력
	 * (검색조건 : boardType , boardName)
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<AdminManageBoardVO> searchBoardNameByPaging(int page, String boardType, String boardName) {
		HashMap map = new HashMap();
		map.put("page", page);
		map.put("perPage", Utilities.CONTENT_PER_PAGE);
		map.put("boardType", boardType);
		map.put("boardName", boardName);
		return (ArrayList<AdminManageBoardVO>) sqlmap.queryForList("adminBoard.SearchAdminBoardNameByPage",map);
	}
	
}
